﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NetTookKits.IOCP;

namespace ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            AsyncSocketServer server = AsyncSocketServer.GetInstance();
            server.ClientReceiveCompleteV += new RaiseSocketRequest(ClientReceiveCompleteP);
            server.ClientConnectedV += new RaiseSocketRequest(ClientConnectedP);
            server.ClientDisConnectedV += new RaiseSocketRequest(ClientDisConnectedP);
            server.startWork("10.175.13.88", 8888);
            Console.WriteLine("server started ...");
            Console.Read();
        }

        public static void ClientReceiveCompleteP(AsyncSocketClient userToken)
        {
            string res = Encoding.Default.GetString(userToken.ReceiveBuffer,0, userToken.ReceiveEventArgs.BytesTransferred);
            userToken.ClearRecvBuffer();
            Console.WriteLine(res);
        }
        public static void ClientConnectedP(AsyncSocketClient userToken)
        {
            Console.WriteLine("Client "+ userToken.ConnectSocket.RemoteEndPoint.ToString()+" connected");
        }
        public static void ClientDisConnectedP(AsyncSocketClient userToken)
        {
            Console.WriteLine("Client " + userToken.ConnectSocket.RemoteEndPoint.ToString() + " disconnected");
        }
    }
}
